package com.gjy.pd.factorysimple;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2022-12-15 09:27:44
 */
public abstract class SimpleFactoryPro extends SimpleFactory {

    public static SimpleProduct getProduct(Class<? extends SimpleProduct> clazz, String... initargs) {
        try {
            if (clazz.getName().equals("com.gjy.pd.simplefactory.ProductC")) {
                if (initargs.length != 1) {
                    throw new IllegalArgumentException();
                }
                return clazz.getDeclaredConstructor(String.class).newInstance(initargs[0]);
            } else {
                return clazz.newInstance();
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}
